package com.yoomiito.app.share.presenter;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.model.bean.GoodsShareInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.share.ui.GoodsShareActivity;
import com.yoomiito.app.utils.NetworkUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class SharePresenter extends BaseActPresenter<GoodsShareActivity> {

    public SharePresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getShareInfo(String id,int goodsType){
        if (NetworkUtils.checkNetPermission(getV())){
            return;
        }
        getV().showLoading();
        YmApi.getYmService()
                .getShareDetail(id,goodsType)
                .compose(getV().bindToLifecycle())
                .compose(XApi.<GoodsShareInfo>getApiTransformerData())
                .compose(XApi.<GoodsShareInfo>getScheduler())
                .subscribe(new ApiSubscriber<GoodsShareInfo>(handleException()) {
                    @Override
                    public void onSuccess(GoodsShareInfo goodsShareInfo) {
                        getV().setData(goodsShareInfo);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        getV().onBackPressed();
                        getV().dismissLoading();
                    }
                });
    }

}
